package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /*@Insert("INSERT INTO setmeal(id, category_id, name, price, status, description, image, create_time, update_time, " +
            "create_user, update_user)" +
            "values (#{id},#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime}," +
            "#{createUser},#{updateUser})")*/
    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal getById(Long id);

    /**
     * 动态更新菜品
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Select("select c.name as categoryName from setmeal s left join category c on s.category_id = c.id " +
            "where s.id=#{id}")
    String getCategoryNameById(Long id);

    /**
     * 批量删除套餐
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    @Select("select * from setmeal where category_id=#{categoryId} and status=#{status}")
    List<Setmeal> getBySetmeal(Setmeal setmeal);

    /**
     * 根据状态查询套餐数量
     * @param status
     * @return
     */
    @Select("select count(*) from setmeal where status=#{status}")
    Integer getNumByStatus(Integer status);

}
